﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Fly.Common.Linq;
using Newtonsoft.Json;
using RN.ERP.Web.Utilities;
using RN.ERP.Web.ModelService;

namespace RN.ERP.Web.Enterprise
{
    public partial class EnterpriseAnnualInspection : System.Web.UI.Page
    {
        protected string ImgBrowseUrl
        {
            get
            {
                if (System.Configuration.ConfigurationManager.AppSettings["ImgBrowseUrl"] != null)
                {
                    return System.Configuration.ConfigurationManager.AppSettings["ImgBrowseUrl"].ToString();
                }
                return string.Empty;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (!IsPostBack)
                {
                    Initial();
                }
            }
            catch { }
        }

        private void Initial()
        {
            string funcCode = string.Empty;////模板Code
            string parameters = string.Empty;////模板动态数据
            string fileName = string.Empty;////文件名称
            Guid userGuid = Guid.Empty;
            if (Request.Params["funcCode"] != null)
            {
                funcCode = Request.Params["funcCode"].Trim();
            }
            if (Request.Params["parameters"] != null)
            {
                parameters = Server.UrlDecode(Request.Params["parameters"].Trim());
            }
            if (Request.Params["fileName"] != null)
            {
                fileName = Request.Params["fileName"].Trim();
            }
            if (Request.Params["userGuid"] != null)
            {
                Guid.TryParse(Request.Params["userGuid"].Trim(), out userGuid);
            }
            ViewState["funcCode"] = funcCode;
            ViewState["parameters"] = parameters;
            ViewState["fileName"] = fileName + ".pdf";
            if (string.IsNullOrEmpty(fileName) || string.IsNullOrEmpty(parameters) || string.IsNullOrEmpty(funcCode))
            {
                //lblMessage.Visible = true;
            }
            GetCorpInfo(userGuid, "14");
        }

        private void GetCorpInfo(Guid userGuid, string areaCode)
        {
            if (userGuid == Guid.Empty)
            {
                return;
            }
            using (EnterpriseService.EnterpriseServiceClient client = new EnterpriseService.EnterpriseServiceClient())
            {
                List<QueryCompanyInfoCondition> listCondition = new List<QueryCompanyInfoCondition>();
                QueryCompanyInfoCondition companyInfoQuery = new QueryCompanyInfoCondition();
                companyInfoQuery.CorpUserGuid = new Fly.Common.Linq.ParameterValue<Guid>() { O = OptEnum.Equal, V = userGuid };
                listCondition.Add(companyInfoQuery);
                var companyInfo = JsonConvert.DeserializeObject<Tb_Corp_CompanyInfo>(client.GetCompanyInfo(JsonConvert.SerializeObject(listCondition), areaCode));
                List<Tb_Corp_CompanyInfo> list = new List<Tb_Corp_CompanyInfo>();
                list.Add(companyInfo);
                CorpInfo.DataSource = list;
                CorpInfo.DataBind();
            }

        }
    }
}